Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ircam/parameters

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ircam/parameters

Tiny and extendable library for class parameters type checking and reflection

  • 1.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

@ircam/parameters

Tiny and extendable library for class parameters type checking and reflection.

Install

npm install [--save] @ircam/parameters

Usage

import parameters from '@ircam/parameters'

const definitions = {
  myBooleanParam: {
    type: 'boolean',
    default: false,
    constant: false,
    metas: { kind: 'static' }
  },
  myIntegerParam: {
    type: 'integer',
    min: 0,
    max: Infinity,
    default: 0,
    constant: false,
    metas: {
      kind: 'static',
      shortDescr: 'My First Integer Param',
      fullDescr: 'This parameter is my first integer parameter in this example.',
      unit: '%',
      step: 1,
      max: 100,
    }
  },
  // ...
};

class MyClass {
  constructor(options) {
    this.params = parameters(definitions, options);

    this.params.addListener((name, value, metas) => {
      // ...
    });

    this.params.addParamListener('myIntegerParam', (value, metas) => {
      // ...
    });
  }
}

const myInstance = new MyClass({ myIntegerParam: 42 });

const bValue = myInstance.params.get('myBooleanParam');
> false

const iValue = myInstance.params.get('myIntegerParam');
> 42

myInstance.params.set('myIntegerParam', definitions.myIntegerParam.min - 1);

API

ParameterBag

Bag of parameters. Main interface of the library

Kind: global class

parameterBag.getDefinitions() ⇒ Object

Return the given definitions along with the initialization values.

Kind: instance method of ParameterBag

parameterBag.getValues() ⇒ Object

Return values of all parameters as a flat object.

Kind: instance method of ParameterBag

parameterBag.get(name) ⇒ Mixed

Return the value of the given parameter.

Kind: instance method of ParameterBag
Returns: Mixed - - Value of the parameter.

ParamTypeDescription
nameStringName of the parameter.

parameterBag.set(name, value, [forcePropagation]) ⇒ Mixed

Set the value of a parameter. If the value of the parameter is updated (aka if previous value is different from new value) all registered callbacks are registered.

Kind: instance method of ParameterBag
Returns: Mixed - - New value of the parameter.

ParamTypeDefaultDescription
nameStringName of the parameter.
valueMixedValue of the parameter.
[forcePropagation]Booleanfalseif true, propagate value even if the value has not changed.

parameterBag.has(name) ⇒ Boolean

Define if the name parameter exists or not.

Kind: instance method of ParameterBag

ParamTypeDescription
nameStringName of the parameter.

parameterBag.reset([name])

Reset a parameter to its init value. Reset all parameters if no argument.

Kind: instance method of ParameterBag

ParamTypeDefaultDescription
[name]StringName of the parameter to reset.

parameterBag.addListener(callback)

Add listener to all param updates.

Kind: instance method of ParameterBag

ParamTypeDescription
callbackParameterBag~listenerCallackListener to register.

parameterBag.removeListener(callback)

Remove listener from all param changes.

Kind: instance method of ParameterBag

ParamTypeDefaultDescription
callbackParameterBag~listenerCallackListener to remove. If null remove all listeners.

parameterBag.addParamListener(name, callback, [trigger])

Add listener to a given param updates.

Kind: instance method of ParameterBag

ParamTypeDefaultDescription
nameStringParameter name.
callbackparamListenerCallackFunction to apply when the value of the parameter changes.
[trigger]BooleanfalseExecute the callback immediately with current parameter value.

parameterBag.removeParamListener(name, callback)

Remove listener from a given param updates.

Kind: instance method of ParameterBag

ParamTypeDefaultDescription
nameStringParameter name.
callbackparamListenerCallackListener to remove. If null remove all listeners.

ParameterBag~listenerCallback : function

Kind: inner typedef of ParameterBag

ParamTypeDescription
nameStringParameter name.
valueMixedUpdated value of the parameter.
[meta=]ObjectGiven meta data of the parameter.

ParameterBag~paramListenerCallack : function

Kind: inner typedef of ParameterBag

ParamTypeDescription
valueMixedUpdated value of the parameter.
[meta=]ObjectGiven meta data of the parameter.

parameters(definitions, values) ⇒ ParameterBag

Factory for the ParameterBag class.

Kind: global function

ParamTypeDescription
definitions[ 'Object' ].<String, paramDefinition>Object describing the parameters.
values[ 'Object' ].<String, Mixed>Initialization values for the parameters.

parameters.defineType(typeName, parameterDefinition)

Register a new type for the parameters factory.

Kind: static method of parameters

ParamTypeDescription
typeNameStringValue that will be available as the type of a param definition.
parameterDefinitionparameterDefinitionObject describing the parameter.

booleanDefinition : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString'boolean'Define a boolean parameter.
defaultBooleanDefault value of the parameter.
constantBooleanfalseDefine if the parameter is constant.
nullableBooleanfalseDefine if the parameter is nullable.
eventBooleantrueDefine if the parameter is a volatile, e.g. set its value back to null after propagation of its value. When true, nullable is automatically set to true and default to null.
metasObject{}Optionnal metadata of the parameter.

integerDefinition : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString'integer'Define a boolean parameter.
defaultMixedDefault value of the parameter.
minNumber-InfinityMinimum value of the parameter.
maxNumber+InfinityMaximum value of the parameter.
constantBooleanfalseDefine if the parameter is constant.
nullableBooleanfalseDefine if the parameter is nullable.
eventBooleantrueDefine if the parameter is a volatile, e.g. set its value back to null after propagation of its value. When true, nullable is automatically set to true and default to null.
metasObject{}Optionnal metadata of the parameter.

floatDefinition : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString'float'Define a boolean parameter.
defaultMixedDefault value of the parameter.
minNumber-InfinityMinimum value of the parameter.
maxNumber+InfinityMaximum value of the parameter.
constantBooleanfalseDefine if the parameter is constant.
nullableBooleanfalseDefine if the parameter is nullable.
eventBooleantrueDefine if the parameter is a volatile, e.g. set its value back to null after propagation of its value. When true, nullable is automatically set to true and default to null.
metasObject{}Optionnal metadata of the parameter.

stringDefinition : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString'string'Define a boolean parameter.
defaultMixedDefault value of the parameter.
constantBooleanfalseDefine if the parameter is constant.
nullableBooleanfalseDefine if the parameter is nullable.
eventBooleantrueDefine if the parameter is a volatile, e.g. set its value back to null after propagation of its value. When true, nullable is automatically set to true and default to null.
metasObject{}Optionnal metadata of the parameter.

enumDefinition : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString'enum'Define a boolean parameter.
defaultMixedDefault value of the parameter.
listArrayPossible values of the parameter.
constantBooleanfalseDefine if the parameter is constant.
nullableBooleanfalseDefine if the parameter is nullable.
eventBooleantrueDefine if the parameter is a volatile, e.g. set its value back to null after propagation of its value. When true, nullable is automatically set to true and default to null.
metasObject{}Optionnal metadata of the parameter.

anyDefinition : Object

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString'enum'Define a parameter of any type.
defaultMixedDefault value of the parameter.
constantBooleanfalseDefine if the parameter is constant.
nullableBooleanfalseDefine if the parameter is nullable.
eventBooleantrueDefine if the parameter is a volatile, e.g. set its value back to null after propagation of its value. When true, nullable is automatically set to true and default to null.
metasObject{}Optionnal metadata of the parameter.

License

BSD-3-Clause

Keywords

FAQs

Package last updated on 31 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc